package edu.lingnan.blog.user.service.impl;


import edu.lingnan.blog.common.core.constant.UserConstants;
import edu.lingnan.blog.common.core.domain.pojo.User;
import edu.lingnan.blog.user.mapper.UserMapper;
import edu.lingnan.blog.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author cql
 */
@Service
public class UserServiceImpl implements UserService {


    @Autowired
    private UserMapper userMapper;

    @Override
    public User selectUserByAccount(String account) {
        return userMapper.selectUserByAccount(account);
    }

    @Override
    public String checkUserNameUnique(String account) {
        int count = userMapper.checkUserNameUnique(account);
        if (count > 0) {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    @Override
    public boolean registerUser(User user) {
        /**
         * TODO 还需要分配用户角色
         */
        return userMapper.insertUser(user) > 0;
    }

    @Override
    public User selectUserById(Integer userId) {
        return userMapper.selectUserById(userId);
    }
}
